<#import "/layout/mainLayout.html" as mainLayout />

<#macro mainheading>

    <link href="/plugins/ztree/zTreeStyle.css" rel="stylesheet"/>
</#macro>
<#assign mainheading = mainheading in mainLayout />

<#macro maincontent>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">

                    <div class="col-xs-8">
                        <div class="box-primary">

                            <!-- form start -->
                            <form id="bannerform" class="form-horizontal" method="post"
                                  enctype="multipart/form-data">
                                <div class="" box-body id="box-body">

                                    <div class="form-group">
                                        <label for="title"
                                               class="col-sm-2 control-label">标题
                                        </label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control"
                                                   name="title"
                                                   id="title"
                                                   placeholder="名称">
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <label for="url"
                                               class="col-sm-2 control-label">URL链接
                                        </label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control"
                                                   name="url"
                                                   id="url"
                                                   placeholder="url链接">
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <div class="col-sm-2">
                                        </div>
                                        <div class="col-sm-2">
                                            <img id="ImgPr"
                                                 class="ImgPr"
                                                 width="120"
                                                 height="120"/>
                                        </div>
                                        <label class="col-sm-2 control-label"
                                               for="film_pic">选择图片
                                        </label>
                                        <div class="col-sm-4">
                                            <input type="file"
                                                   id="film_pic"
                                                   name="film_pic">
                                        </div>

                                    </div>
                                </div><!-- /.box-body -->
                                <div class="box-footer">
                                    <button type="button" class="btn btn-info pull-right"
                                            onclick="addBanner()">添加
                                    </button>
                                </div><!-- /.box-footer -->
                            </form>
                        </div>
                    </div>
                </div><!-- /.box -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </section>

</#macro>
<#assign maincontent = maincontent in mainLayout />

<#macro mainfooter>
    <script src="/js/jquery/jquery.form.js"></script>

    <script type="text/javascript" src="/plugins/ztree/jquery.ztree.all-3.5.min.js"></script>

    <script src="/js/mortise/funcTree.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#film_pic").uploadPreview({Img: "ImgPr", Width: 120, Height: 120});
        });
        function addBanner() {

            if (!$('#title').val()) {
                dialog({
                    title: '提示',
                    content: '请输入标题！',
                    cancel: false,
                    ok: function () {
                    }
                }).width(320).showModal();
                return;
            }

            var options = {
                url: '/api/banner/add',
                type:'post',
                success: function (data) {
                    if (data) {
                        if (data.code=='OperateOk') {
                            dialog({
                                title: '提示',
                                content: '操作成功！',
                                cancel: false,
                                ok: function () {
                                }
                            }).width(320).showModal();
                        }
                        else {
                            dialog({
                                title: '提示',
                                content: '操作失败！',
                                cancel: false,
                                ok: function () {
                                }
                            }).width(320).showModal();
                        }
                    }
                }
            };
            $("#bannerform").ajaxSubmit(options);
        }
    </script>
</#macro>
<#assign mainfooter = mainfooter in mainLayout />
<@mainLayout.page title="用户管理"/>